
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>YUI Library Examples: JSON: Adding New Object Members During Parsing</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    	<link rel="stylesheet" type="text/css" href="../../assets/yui.css" >

<style>
    /*Supplemental CSS for the YUI distribution*/
    #custom-doc { width: 95%; min-width: 950px; }
    #pagetitle {background-image: url(../../assets/bg_hd.gif);}
/*    #pagetitle h1 {background-image: url(../../assets/title_h_bg.gif);}*/
</style>

<link rel="stylesheet" type="text/css" href="../../assets/dpSyntaxHighlighter.css">

<!--there is no custom header content for this example-->

<link type="text/css" rel="stylesheet" href="../../build/cssfonts/fonts-min.css" />
<script type="text/javascript" src="../../build/yui/yui-min.js"></script>

</head>
<body id="yahoo-com" class="yui3-skin-sam  yui-skin-sam">
<div id="custom-doc" class="yui-t2">
<div id="hd">
	<div id="ygunav">
		<p>
            <em>
                <a href="http://developer.yahoo.com/yui/3/">YUI 3.x Home</a> <i> - </i>	
            </em>
		</p>
		<form action="http://search.yahoo.com/search" id="sitesearchform">
            <input name="vs" type="hidden" value="developer.yahoo.com">
            <input name="vs" type="hidden" value="yuiblog.com">
			<input name="vs" type="hidden" value="yuilibrary.com">
		    <div id="sitesearch">
		    	<label for="searchinput">Site Search (YDN, YUILibrary &amp; YUIBlog): </label>
			    <input type="text" id="searchinput" name="p">
			    <input type="submit" value="Search" id="searchsubmit" class="ygbt">
		    </div>
		</form>
    </div>
	<div id="ygma"><a href="../../"><img src="../../assets/logo.gif"  border="0" width="200" height="93"></a></div>
	<div id="pagetitle"><h1>YUI Library Examples: JSON: Adding New Object Members During Parsing</h1></div>
</div>
<div id="bd">


	<div id="yui-main">
		<div class="yui-b">
		  <div class="yui-ge">
			  <div class="yui-u first example" id="main">

	<h2>JSON: Adding New Object Members During Parsing</h2>

	<div id="example" class="promo">
	<div class="example-intro">
	<p>This example shows how to use the <code>reviver</code> parameter in <code>JSON.parse</code> to add new object members and format existing members during the parsing phase.</p>
	</div>

	<div class="module example-container ">
			<div class="hd exampleHd">
			<p class="newWindowButton yui-skin-sam">
                <a href="json_convert_values_clean.html" target="_blank">View example in new window.</a>
            </p>
		</div>		<div id="example-canvas" class="bd">

	
	<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

	<div id="demo">
    <p>Choose a currency, then get the data</p>
    <select>
        <option value="ARS">Argentine Peso</option>
        <option value="AUD">Australian Dollar</option>
        <option value="BRL">Brazilian Real</option>
        <option value="GBP">British Pound</option>
        <option value="CAD">Canadian Dollar</option>
        <option value="CNY">Chinese Yuan</option>
        <option value="COP">Colombian Peso</option>
        <option value="HRK">Croatian Kuna</option>
        <option value="CZK">Czech Koruna</option>
        <option value="DKK">Danish Krone</option>
        <option value="EEK">Estonian Kroon</option>
        <option value="EUR">Euro</option>
        <option value="HKD">Hong Kong Dollar</option>
        <option value="HUF">Hungarian Forint</option>
        <option value="ISK">Iceland Krona</option>
        <option value="INR">Indian Rupee</option>
        <option value="JPY">Japanese Yen</option>
        <option value="KRW">Korean Won</option>
        <option value="LVL">Latvian Lat</option>
        <option value="LTL">Lithuanian Lita</option>
        <option value="MYR">Malaysian Ringgit</option>
        <option value="MXN">Mexican Peso</option>
        <option value="NZD">New Zealand Dollar</option>
        <option value="NOK">Norwegian Krone</option>
        <option value="PHP">Philippine Peso</option>
        <option value="PLN">Polish Zloty</option>
        <option value="RUB">Russian Rouble</option>
        <option value="SGD">Singapore Dollar</option>
        <option value="SKK">Slovak Koruna</option>
        <option value="ZAR">South African Rand</option>
        <option value="LKR">Sri Lanka Rupee</option>
        <option value="SEK">Swedish Krona</option>
        <option value="TRY">Turkey Lira</option>
        <option value="USD" selected="selected">U.S. Dollar</option>
        <option value="CHF">Swiss Franc</option>
        <option value="TWD">Taiwan Dollar</option>
        <option value="THB">Thai Baht</option>
    </select>
    <input type="button" id="demo_go" value="Get Data">

    <table cellspacing="0">
    <caption>Inventory</caption>
    <thead>
        <tr>
            <th>SKU</th>
            <th>Item</th>
            <th>Price (USD)</th>
            <th>Price (<span>USD</span>)</th>
        </tr>
    </thead>
    <tbody>
        <tr><td colspan="4">Click <em>Get Data</em></td></tr>
    </tbody>
    </table>
</div>

<script type="text/javascript">
YUI({ filter: 'raw' }).use("node", "io", "json-parse",function (Y) {

// Safari 4.0.3's native JSON does not support adding members during parse,
// so use JavaScript implementation for consistency
Y.JSON.useNativeParse = false;

var example = {
    rates : {"USD":1,"EUR":0.6661,"GBP":0.5207,"AUD":1.1225,"BRL":1.609,"NZD":1.4198,"CAD":1.0667,"CHF":1.0792,"CNY":6.8587 ,"DKK":4.9702,"HKD":7.8064,"INR":42.0168,"JPY":109.8901,"KRW":1000,"LKR":107.5269,"MXN":10.1317,"MYR" :3.3167,"NOK":5.3277,"SEK":6.2617,"SGD":1.4073,"THB":33.7838,"TWD":31.1526,"VEF":2.1445,"ZAR":7.6923 ,"BGN":1.3028,"CZK":16.0514,"EEK":10.4275,"HUF":158.7302,"LTL":2.2999,"LVL":0.4692,"PLN":2.1758,"RON" :2.3804,"SKK":20.2429,"ISK":4.8008,"HRK":81.3008,"RUB":24.3309,"TRY":1.1811,"PHP":44.2478,"COP":2000 ,"ARS":3.1289},

    currency : 'USD',

    convert : function (k,v) {
        // 'this' will refer to the object containing the key:value pair,
        // so this step will add a new object member while leaving the original
        // intact (but formatted to two decimal places).  If the original
        // is not needed, just return the converted value.
        if (k === 'Price') {
            var x = Math.round(v * example.rates[example.currency] * 100) / 100;
            this.convertedPrice = x.toFixed(2); // added to item
            return v.toFixed(2); // assigned to item.Price
        }
        return v;
    },

    updateTable : function (inventory) {
        // Update the column header
        Y.one('#demo table th span').set('innerHTML',example.currency);

        var tbody = Y.one('#demo table tbody'),
            html  = ['<tbody>'],
            rowTemplate = '<tr><td>{SKU}</td><td>{Item}</td><td>{Price}</td><td>{convertedPrice}</td></tr>',
            i, len;

        if (inventory) {
            for (i = 0, len = inventory.length; i < len; ++i) {
                html.push(Y.Lang.sub(rowTemplate, inventory[i]));
            }
        } else {
            html.push('<tr><td colspan="4">No Inventory data</td></tr>');
        }

        html.push('</tbody>');

        tbody.replace(html.join(''));
    }
};

Y.one('#demo_go').on('click', function (e) {
    // Disable the button temporarily
    this.set('disabled',true);

    // Store the requested currency
    var sel = Y.one("#demo select");
    example.currency = sel.get("options").item(sel.get("selectedIndex")).get("value");

    Y.io('assets/data.php',{
        timeout : 3000,
        on : {
            success : function (xid, res) {
                var inventory;
                try {
                    inventory = Y.JSON.parse(res.responseText,example.convert);

                    example.updateTable(inventory);
                }
                catch(e) {
                    alert("Error getting inventory data");
                }
                finally {
                    Y.one('#demo_go').set('disabled',false);
                }
            },
            failure : function () {
                alert("Error getting inventory data");
            }
        }
    });
});

// Expose example objects for inspection
YUI.example = example;
});
</script>
</script>

	<!--END SOURCE CODE FOR EXAMPLE =============================== -->

	
		</div>
	</div>
	</div>

	<h3>The data</h3>
<p>The data returned from the server will be a JSON string containing this object structure:</p>
<div id="syntax-dd04ba584213913a90ad9a4133ceb744" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="br0">&#91;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;23-23874&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">23.99</span><span class="sy0">,</span>  <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Helmet&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;48-38835&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">14.97</span><span class="sy0">,</span>  <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Football&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;84-84848&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">3.49</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Goggles&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;84-84843&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">183</span><span class="sy0">,</span>    <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Badminton Set&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;84-39321&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">6.79</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Tennis Balls&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;39-48949&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">618</span><span class="sy0">,</span>    <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Snowboard&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;99-28128&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">78.99</span><span class="sy0">,</span>  <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Cleats&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;83-48281&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">4.69</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Volleyball&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;89-32811&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">0.59</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Sweatband&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;28-22847&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">779.98</span><span class="sy0">,</span> <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Golf Set&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;38-38281&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">8.25</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Basketball Shorts&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;82-38333&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">1.39</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Lip balm&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;21-38485&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">0.07</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Ping Pong ball&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2">    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;83-38285&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">3.99</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Hockey Puck&quot;</span><span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#93;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;"><span class="br0">&#91;</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;23-23874&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">23.99</span><span class="sy0">,</span>  <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Helmet&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;48-38835&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">14.97</span><span class="sy0">,</span>  <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Football&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;84-84848&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">3.49</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Goggles&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;84-84843&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">183</span><span class="sy0">,</span>    <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Badminton Set&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;84-39321&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">6.79</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Tennis Balls&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;39-48949&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">618</span><span class="sy0">,</span>    <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Snowboard&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;99-28128&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">78.99</span><span class="sy0">,</span>  <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Cleats&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;83-48281&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">4.69</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Volleyball&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;89-32811&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">0.59</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Sweatband&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;28-22847&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">779.98</span><span class="sy0">,</span> <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Golf Set&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;38-38281&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">8.25</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Basketball Shorts&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;82-38333&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">1.39</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Lip balm&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;21-38485&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">0.07</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Ping Pong ball&quot;</span><span class="br0">&#125;</span><span class="sy0">,</span>
    <span class="br0">&#123;</span><span class="st0">&quot;SKU&quot;</span><span class="sy0">:</span><span class="st0">&quot;83-38285&quot;</span><span class="sy0">,</span> <span class="st0">&quot;Price&quot;</span><span class="sy0">:</span><span class="nu0">3.99</span><span class="sy0">,</span>   <span class="st0">&quot;Item&quot;</span><span class="sy0">:</span><span class="st0">&quot;Hockey Puck&quot;</span><span class="br0">&#125;</span>
<span class="br0">&#93;</span></pre></div><textarea id="syntax-dd04ba584213913a90ad9a4133ceb744-plain">[
    {"SKU":"23-23874", "Price":23.99,  "Item":"Helmet"},
    {"SKU":"48-38835", "Price":14.97,  "Item":"Football"},
    {"SKU":"84-84848", "Price":3.49,   "Item":"Goggles"},
    {"SKU":"84-84843", "Price":183,    "Item":"Badminton Set"},
    {"SKU":"84-39321", "Price":6.79,   "Item":"Tennis Balls"},
    {"SKU":"39-48949", "Price":618,    "Item":"Snowboard"},
    {"SKU":"99-28128", "Price":78.99,  "Item":"Cleats"},
    {"SKU":"83-48281", "Price":4.69,   "Item":"Volleyball"},
    {"SKU":"89-32811", "Price":0.59,   "Item":"Sweatband"},
    {"SKU":"28-22847", "Price":779.98, "Item":"Golf Set"},
    {"SKU":"38-38281", "Price":8.25,   "Item":"Basketball Shorts"},
    {"SKU":"82-38333", "Price":1.39,   "Item":"Lip balm"},
    {"SKU":"21-38485", "Price":0.07,   "Item":"Ping Pong ball"},
    {"SKU":"83-38285", "Price":3.99,   "Item":"Hockey Puck"}
]</textarea></div>
<h3>Create a reviver function</h3>
<p>We'll contain all the moving parts in an <code>example</code> namespace.  In it, we'll include the currency exchange rates and a function to reference the rates to add a new member to the JSON response as it is being parsed.</p>
<div id="syntax-ef42e139d9fa370a0c4f383971b04524" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1">YUI<span class="br0">&#40;</span><span class="br0">&#123;</span> filter<span class="sy0">:</span> <span class="st0">'raw'</span> <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="kw2">use</span><span class="br0">&#40;</span><span class="st0">&quot;node&quot;</span><span class="sy0">,</span> <span class="st0">&quot;io&quot;</span><span class="sy0">,</span> <span class="st0">&quot;json-parse&quot;</span><span class="sy0">,</span><span class="kw2">function</span> <span class="br0">&#40;</span>Y<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="kw2">var</span> example <span class="sy0">=</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    rates <span class="sy0">:</span> <span class="br0">&#123;</span><span class="st0">&quot;USD&quot;</span><span class="sy0">:</span><span class="nu0">1</span><span class="sy0">,</span><span class="st0">&quot;EUR&quot;</span><span class="sy0">:</span><span class="nu0">0.6661</span><span class="sy0">,</span>...<span class="sy0">,</span><span class="st0">&quot;COP&quot;</span><span class="sy0">:</span><span class="nu0">2000</span> <span class="sy0">,</span><span class="st0">&quot;ARS&quot;</span><span class="sy0">:</span><span class="nu0">3.1289</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1">    currency <span class="sy0">:</span> <span class="st0">'USD'</span><span class="sy0">,</span> <span class="co1">// updated by the select element</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    convert <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span>k<span class="sy0">,</span>v<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="co1">// 'this' will refer to the object containing the key:value pair,</span></div></li><li class="li2"><div class="de2">        <span class="co1">// so this step will add a new object member while leaving the original</span></div></li><li class="li1"><div class="de1">        <span class="co1">// intact (but formatted to two decimal places).  If the original</span></div></li><li class="li1"><div class="de1">        <span class="co1">// is not needed, just return the converted value.</span></div></li><li class="li1"><div class="de1">        <span class="kw1">if</span> <span class="br0">&#40;</span>k <span class="sy0">===</span> <span class="st0">'Price'</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">            <span class="kw2">var</span> x <span class="sy0">=</span> Math.<span class="me1">round</span><span class="br0">&#40;</span>v <span class="sy0">*</span> example.<span class="me1">rates</span><span class="br0">&#91;</span>example.<span class="me1">currency</span><span class="br0">&#93;</span> <span class="sy0">*</span> <span class="nu0">100</span><span class="br0">&#41;</span> <span class="sy0">/</span> <span class="nu0">100</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">            <span class="kw1">this</span>.<span class="me1">convertedPrice</span> <span class="sy0">=</span> x.<span class="me1">toFixed</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// added to item</span></div></li><li class="li1"><div class="de1">            <span class="kw1">return</span> v.<span class="me1">toFixed</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// assigned to item.Price</span></div></li><li class="li1"><div class="de1">        <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">return</span> v<span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2">    ...</div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">...</div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;">YUI<span class="br0">&#40;</span><span class="br0">&#123;</span> filter<span class="sy0">:</span> <span class="st0">'raw'</span> <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="kw2">use</span><span class="br0">&#40;</span><span class="st0">&quot;node&quot;</span><span class="sy0">,</span> <span class="st0">&quot;io&quot;</span><span class="sy0">,</span> <span class="st0">&quot;json-parse&quot;</span><span class="sy0">,</span><span class="kw2">function</span> <span class="br0">&#40;</span>Y<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
<span class="kw2">var</span> example <span class="sy0">=</span> <span class="br0">&#123;</span>
    rates <span class="sy0">:</span> <span class="br0">&#123;</span><span class="st0">&quot;USD&quot;</span><span class="sy0">:</span><span class="nu0">1</span><span class="sy0">,</span><span class="st0">&quot;EUR&quot;</span><span class="sy0">:</span><span class="nu0">0.6661</span><span class="sy0">,</span>...<span class="sy0">,</span><span class="st0">&quot;COP&quot;</span><span class="sy0">:</span><span class="nu0">2000</span> <span class="sy0">,</span><span class="st0">&quot;ARS&quot;</span><span class="sy0">:</span><span class="nu0">3.1289</span><span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
    currency <span class="sy0">:</span> <span class="st0">'USD'</span><span class="sy0">,</span> <span class="co1">// updated by the select element</span>
&nbsp;
    convert <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span>k<span class="sy0">,</span>v<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="co1">// 'this' will refer to the object containing the key:value pair,</span>
        <span class="co1">// so this step will add a new object member while leaving the original</span>
        <span class="co1">// intact (but formatted to two decimal places).  If the original</span>
        <span class="co1">// is not needed, just return the converted value.</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span>k <span class="sy0">===</span> <span class="st0">'Price'</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="kw2">var</span> x <span class="sy0">=</span> Math.<span class="me1">round</span><span class="br0">&#40;</span>v <span class="sy0">*</span> example.<span class="me1">rates</span><span class="br0">&#91;</span>example.<span class="me1">currency</span><span class="br0">&#93;</span> <span class="sy0">*</span> <span class="nu0">100</span><span class="br0">&#41;</span> <span class="sy0">/</span> <span class="nu0">100</span><span class="sy0">;</span>
            <span class="kw1">this</span>.<span class="me1">convertedPrice</span> <span class="sy0">=</span> x.<span class="me1">toFixed</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// added to item</span>
            <span class="kw1">return</span> v.<span class="me1">toFixed</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// assigned to item.Price</span>
        <span class="br0">&#125;</span>
        <span class="kw1">return</span> v<span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
    ...
<span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
...</pre></div><textarea id="syntax-ef42e139d9fa370a0c4f383971b04524-plain">YUI({ filter: 'raw' }).use("node", "io", "json-parse",function (Y) {

var example = {
    rates : {"USD":1,"EUR":0.6661,...,"COP":2000 ,"ARS":3.1289},

    currency : 'USD', // updated by the select element

    convert : function (k,v) {
        // 'this' will refer to the object containing the key:value pair,
        // so this step will add a new object member while leaving the original
        // intact (but formatted to two decimal places).  If the original
        // is not needed, just return the converted value.
        if (k === 'Price') {
            var x = Math.round(v * example.rates[example.currency] * 100) / 100;
            this.convertedPrice = x.toFixed(2); // added to item
            return v.toFixed(2); // assigned to item.Price
        }
        return v;
    },
    ...
};

...</textarea></div>
<h3>Sending the request and parsing the JSON response</h3>
<p>When the <em>Get Data</em> button is clicked, we send an <code>io</code> request for the JSON data, and in our success handler, pass our conversion function to <code>JSON.parse</code> with the response text.  The resulting inventory records will have an additional member, <code>convertedPrice</code>.  This data is then passed to a UI method to update the inventory table.</p>
<div id="syntax-0512005a954b49ae6613cc5878207157" class="yui-syntax-highlight"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1">Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#demo_go'</span><span class="br0">&#41;</span>.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'click'</span><span class="sy0">,</span> <span class="kw2">function</span> <span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="co1">// Disable the button temporarily</span></div></li><li class="li1"><div class="de1">    <span class="kw1">this</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'disabled'</span><span class="sy0">,</span><span class="kw2">true</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li2"><div class="de2">    <span class="co1">// Store the requested currency</span></div></li><li class="li1"><div class="de1">    <span class="kw2">var</span> sel <span class="sy0">=</span> Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">&quot;#demo select&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    example.<span class="me1">currency</span> <span class="sy0">=</span> sel.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;options&quot;</span><span class="br0">&#41;</span>.<span class="kw1">item</span><span class="br0">&#40;</span>sel.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;selectedIndex&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="co1">// Send the request for the JSON data</span></div></li><li class="li2"><div class="de2">    Y.<span class="me1">io</span><span class="br0">&#40;</span><span class="st0">'assets/data.php'</span><span class="sy0">,</span><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        timeout <span class="sy0">:</span> <span class="nu0">3000</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">        on <span class="sy0">:</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">            success <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span>xid<span class="sy0">,</span> res<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                <span class="kw2">var</span> inventory<span class="sy0">;</span></div></li><li class="li2"><div class="de2">                <span class="kw1">try</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                    inventory <span class="sy0">=</span> Y.<span class="me1">JSON</span>.<span class="me1">parse</span><span class="br0">&#40;</span>res.<span class="me1">responseText</span><span class="sy0">,</span>example.<span class="me1">convert</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">                    example.<span class="me1">updateTable</span><span class="br0">&#40;</span>inventory<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">                <span class="br0">&#125;</span></div></li><li class="li2"><div class="de2">                <span class="kw1">catch</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                    <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Error getting inventory data&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">                <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">                <span class="kw1">finally</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                    Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#demo_go'</span><span class="br0">&#41;</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'disabled'</span><span class="sy0">,</span><span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">                <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">            <span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">            failure <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Error getting inventory data&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="br0">&#125;</span></div></li><li class="li2"><div class="de2">        <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// End YUI(..).use(..,function (Y) {</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;">Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#demo_go'</span><span class="br0">&#41;</span>.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'click'</span><span class="sy0">,</span> <span class="kw2">function</span> <span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="co1">// Disable the button temporarily</span>
    <span class="kw1">this</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'disabled'</span><span class="sy0">,</span><span class="kw2">true</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="co1">// Store the requested currency</span>
    <span class="kw2">var</span> sel <span class="sy0">=</span> Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">&quot;#demo select&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    example.<span class="me1">currency</span> <span class="sy0">=</span> sel.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;options&quot;</span><span class="br0">&#41;</span>.<span class="kw1">item</span><span class="br0">&#40;</span>sel.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;selectedIndex&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="co1">// Send the request for the JSON data</span>
    Y.<span class="me1">io</span><span class="br0">&#40;</span><span class="st0">'assets/data.php'</span><span class="sy0">,</span><span class="br0">&#123;</span>
        timeout <span class="sy0">:</span> <span class="nu0">3000</span><span class="sy0">,</span>
        on <span class="sy0">:</span> <span class="br0">&#123;</span>
            success <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span>xid<span class="sy0">,</span> res<span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="kw2">var</span> inventory<span class="sy0">;</span>
                <span class="kw1">try</span> <span class="br0">&#123;</span>
                    inventory <span class="sy0">=</span> Y.<span class="me1">JSON</span>.<span class="me1">parse</span><span class="br0">&#40;</span>res.<span class="me1">responseText</span><span class="sy0">,</span>example.<span class="me1">convert</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
                    example.<span class="me1">updateTable</span><span class="br0">&#40;</span>inventory<span class="br0">&#41;</span><span class="sy0">;</span>
                <span class="br0">&#125;</span>
                <span class="kw1">catch</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
                    <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Error getting inventory data&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
                <span class="br0">&#125;</span>
                <span class="kw1">finally</span> <span class="br0">&#123;</span>
                    Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#demo_go'</span><span class="br0">&#41;</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'disabled'</span><span class="sy0">,</span><span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span>
                <span class="br0">&#125;</span>
            <span class="br0">&#125;</span><span class="sy0">,</span>
            failure <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Error getting inventory data&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="br0">&#125;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// End YUI(..).use(..,function (Y) {</span></pre></div><textarea id="syntax-0512005a954b49ae6613cc5878207157-plain">Y.one('#demo_go').on('click', function (e) {
    // Disable the button temporarily
    this.set('disabled',true);

    // Store the requested currency
    var sel = Y.one("#demo select");
    example.currency = sel.get("options").item(sel.get("selectedIndex")).get("value");

    // Send the request for the JSON data
    Y.io('assets/data.php',{
        timeout : 3000,
        on : {
            success : function (xid, res) {
                var inventory;
                try {
                    inventory = Y.JSON.parse(res.responseText,example.convert);

                    example.updateTable(inventory);
                }
                catch(e) {
                    alert("Error getting inventory data");
                }
                finally {
                    Y.one('#demo_go').set('disabled',false);
                }
            },
            failure : function () {
                alert("Error getting inventory data");
            }
        }
    });
});

}); // End YUI(..).use(..,function (Y) {</textarea></div>
<h3>Example markup</h3>
<div id="syntax-068a56e57e2ed801e0170b08c76afde0" class="yui-syntax-highlight"><div class="numbers"><pre class="html4strict" style="font-family:monospace;"><ol><li class="li1"><div class="de1"><span class="sc2">&lt;<span class="kw2">div</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;demo&quot;</span>&gt;</span></div></li><li class="li1"><div class="de1">    <span class="sc2">&lt;<span class="kw2">p</span>&gt;</span>Choose a currency, then get the data<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">p</span>&gt;</span></div></li><li class="li1"><div class="de1">    <span class="sc2">&lt;<span class="kw2">select</span>&gt;</span></div></li><li class="li1"><div class="de1">        <span class="sc2">&lt;<span class="kw2">option</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;ARS&quot;</span>&gt;</span>Argentine Peso<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">option</span>&gt;</span></div></li><li class="li2"><div class="de2">        <span class="sc2">&lt;<span class="kw2">option</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;AUD&quot;</span>&gt;</span>Australian Dollar<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">option</span>&gt;</span></div></li><li class="li1"><div class="de1">        ...</div></li><li class="li1"><div class="de1">        <span class="sc2">&lt;<span class="kw2">option</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;TWD&quot;</span>&gt;</span>Taiwan Dollar<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">option</span>&gt;</span></div></li><li class="li1"><div class="de1">        <span class="sc2">&lt;<span class="kw2">option</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;THB&quot;</span>&gt;</span>Thai Baht<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">option</span>&gt;</span></div></li><li class="li1"><div class="de1">    <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">select</span>&gt;</span></div></li><li class="li2"><div class="de2">    <span class="sc2">&lt;<span class="kw2">input</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;button&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;demo_go&quot;</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;Get Data&quot;</span>&gt;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="sc2">&lt;<span class="kw2">table</span> <span class="kw3">cellspacing</span><span class="sy0">=</span><span class="st0">&quot;0&quot;</span>&gt;</span></div></li><li class="li1"><div class="de1">    <span class="sc2">&lt;<span class="kw2">caption</span>&gt;</span>Inventory<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">caption</span>&gt;</span></div></li><li class="li1"><div class="de1">    <span class="sc2">&lt;<span class="kw2">thead</span>&gt;</span></div></li><li class="li2"><div class="de2">        <span class="sc2">&lt;<span class="kw2">tr</span>&gt;</span></div></li><li class="li1"><div class="de1">            <span class="sc2">&lt;<span class="kw2">th</span>&gt;</span>SKU<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">th</span>&gt;</span></div></li><li class="li1"><div class="de1">            <span class="sc2">&lt;<span class="kw2">th</span>&gt;</span>Item<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">th</span>&gt;</span></div></li><li class="li1"><div class="de1">            <span class="sc2">&lt;<span class="kw2">th</span>&gt;</span>Price (USD)<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">th</span>&gt;</span></div></li><li class="li1"><div class="de1">            <span class="sc2">&lt;<span class="kw2">th</span>&gt;</span>Price (<span class="sc2">&lt;<span class="kw2">span</span>&gt;</span>USD<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">span</span>&gt;</span>)<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">th</span>&gt;</span></div></li><li class="li2"><div class="de2">        <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">tr</span>&gt;</span></div></li><li class="li1"><div class="de1">    <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">thead</span>&gt;</span></div></li><li class="li1"><div class="de1">    <span class="sc2">&lt;<span class="kw2">tbody</span>&gt;</span></div></li><li class="li1"><div class="de1">        <span class="sc2">&lt;<span class="kw2">tr</span>&gt;&lt;<span class="kw2">td</span> <span class="kw3">colspan</span><span class="sy0">=</span><span class="st0">&quot;4&quot;</span>&gt;</span>Click <span class="sc2">&lt;<span class="kw2">em</span>&gt;</span>Get Data<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">em</span>&gt;&lt;<span class="sy0">/</span><span class="kw2">td</span>&gt;&lt;<span class="sy0">/</span><span class="kw2">tr</span>&gt;</span></div></li><li class="li1"><div class="de1">    <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">tbody</span>&gt;</span></div></li><li class="li2"><div class="de2">    <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">table</span>&gt;</span></div></li><li class="li1"><div class="de1"><span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="html4strict" style="font-family:monospace;"><span class="sc2">&lt;<span class="kw2">div</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;demo&quot;</span>&gt;</span>
    <span class="sc2">&lt;<span class="kw2">p</span>&gt;</span>Choose a currency, then get the data<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">p</span>&gt;</span>
    <span class="sc2">&lt;<span class="kw2">select</span>&gt;</span>
        <span class="sc2">&lt;<span class="kw2">option</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;ARS&quot;</span>&gt;</span>Argentine Peso<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">option</span>&gt;</span>
        <span class="sc2">&lt;<span class="kw2">option</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;AUD&quot;</span>&gt;</span>Australian Dollar<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">option</span>&gt;</span>
        ...
        <span class="sc2">&lt;<span class="kw2">option</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;TWD&quot;</span>&gt;</span>Taiwan Dollar<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">option</span>&gt;</span>
        <span class="sc2">&lt;<span class="kw2">option</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;THB&quot;</span>&gt;</span>Thai Baht<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">option</span>&gt;</span>
    <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">select</span>&gt;</span>
    <span class="sc2">&lt;<span class="kw2">input</span> <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;button&quot;</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;demo_go&quot;</span> <span class="kw3">value</span><span class="sy0">=</span><span class="st0">&quot;Get Data&quot;</span>&gt;</span>
&nbsp;
    <span class="sc2">&lt;<span class="kw2">table</span> <span class="kw3">cellspacing</span><span class="sy0">=</span><span class="st0">&quot;0&quot;</span>&gt;</span>
    <span class="sc2">&lt;<span class="kw2">caption</span>&gt;</span>Inventory<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">caption</span>&gt;</span>
    <span class="sc2">&lt;<span class="kw2">thead</span>&gt;</span>
        <span class="sc2">&lt;<span class="kw2">tr</span>&gt;</span>
            <span class="sc2">&lt;<span class="kw2">th</span>&gt;</span>SKU<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">th</span>&gt;</span>
            <span class="sc2">&lt;<span class="kw2">th</span>&gt;</span>Item<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">th</span>&gt;</span>
            <span class="sc2">&lt;<span class="kw2">th</span>&gt;</span>Price (USD)<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">th</span>&gt;</span>
            <span class="sc2">&lt;<span class="kw2">th</span>&gt;</span>Price (<span class="sc2">&lt;<span class="kw2">span</span>&gt;</span>USD<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">span</span>&gt;</span>)<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">th</span>&gt;</span>
        <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">tr</span>&gt;</span>
    <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">thead</span>&gt;</span>
    <span class="sc2">&lt;<span class="kw2">tbody</span>&gt;</span>
        <span class="sc2">&lt;<span class="kw2">tr</span>&gt;&lt;<span class="kw2">td</span> <span class="kw3">colspan</span><span class="sy0">=</span><span class="st0">&quot;4&quot;</span>&gt;</span>Click <span class="sc2">&lt;<span class="kw2">em</span>&gt;</span>Get Data<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">em</span>&gt;&lt;<span class="sy0">/</span><span class="kw2">td</span>&gt;&lt;<span class="sy0">/</span><span class="kw2">tr</span>&gt;</span>
    <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">tbody</span>&gt;</span>
    <span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">table</span>&gt;</span>
<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">div</span>&gt;</span></pre></div><textarea id="syntax-068a56e57e2ed801e0170b08c76afde0-plain"><div id="demo">
    <p>Choose a currency, then get the data</p>
    <select>
        <option value="ARS">Argentine Peso</option>
        <option value="AUD">Australian Dollar</option>
        ...
        <option value="TWD">Taiwan Dollar</option>
        <option value="THB">Thai Baht</option>
    </select>
    <input type="button" id="demo_go" value="Get Data">

    <table cellspacing="0">
    <caption>Inventory</caption>
    <thead>
        <tr>
            <th>SKU</th>
            <th>Item</th>
            <th>Price (USD)</th>
            <th>Price (<span>USD</span>)</th>
        </tr>
    </thead>
    <tbody>
        <tr><td colspan="4">Click <em>Get Data</em></td></tr>
    </tbody>
    </table>
</div></textarea></div>
<h3>Full Code Listing</h3>
<p>Below is the full source for the example.</p>

<div id="syntax-fbd938cb61eb0c597e08c5f48e64f802" class="yui-syntax-highlight yui-syntax-highlight-linenumbers"><div class="numbers"><pre class="javascript" style="font-family:monospace;"><ol><li class="li1"><div class="de1">YUI<span class="br0">&#40;</span><span class="br0">&#123;</span> filter<span class="sy0">:</span> <span class="st0">'raw'</span> <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="kw2">use</span><span class="br0">&#40;</span><span class="st0">&quot;node&quot;</span><span class="sy0">,</span> <span class="st0">&quot;io&quot;</span><span class="sy0">,</span> <span class="st0">&quot;json-parse&quot;</span><span class="sy0">,</span><span class="kw2">function</span> <span class="br0">&#40;</span>Y<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="co1">// Safari 4.0.3's native JSON does not support adding members during parse,</span></div></li><li class="li1"><div class="de1"><span class="co1">// so use JavaScript implementation for consistency</span></div></li><li class="li2"><div class="de2">Y.<span class="me1">JSON</span>.<span class="me1">useNativeParse</span> <span class="sy0">=</span> <span class="kw2">false</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1"><span class="kw2">var</span> example <span class="sy0">=</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    rates <span class="sy0">:</span> <span class="br0">&#123;</span><span class="st0">&quot;USD&quot;</span><span class="sy0">:</span><span class="nu0">1</span><span class="sy0">,</span><span class="st0">&quot;EUR&quot;</span><span class="sy0">:</span><span class="nu0">0.6661</span><span class="sy0">,</span><span class="st0">&quot;GBP&quot;</span><span class="sy0">:</span><span class="nu0">0.5207</span><span class="sy0">,</span><span class="st0">&quot;AUD&quot;</span><span class="sy0">:</span><span class="nu0">1.1225</span><span class="sy0">,</span><span class="st0">&quot;BRL&quot;</span><span class="sy0">:</span><span class="nu0">1.609</span><span class="sy0">,</span><span class="st0">&quot;NZD&quot;</span><span class="sy0">:</span><span class="nu0">1.4198</span><span class="sy0">,</span><span class="st0">&quot;CAD&quot;</span><span class="sy0">:</span><span class="nu0">1.0667</span><span class="sy0">,</span><span class="st0">&quot;CHF&quot;</span><span class="sy0">:</span><span class="nu0">1.0792</span><span class="sy0">,</span><span class="st0">&quot;CNY&quot;</span><span class="sy0">:</span><span class="nu0">6.8587</span> <span class="sy0">,</span><span class="st0">&quot;DKK&quot;</span><span class="sy0">:</span><span class="nu0">4.9702</span><span class="sy0">,</span><span class="st0">&quot;HKD&quot;</span><span class="sy0">:</span><span class="nu0">7.8064</span><span class="sy0">,</span><span class="st0">&quot;INR&quot;</span><span class="sy0">:</span><span class="nu0">42.0168</span><span class="sy0">,</span><span class="st0">&quot;JPY&quot;</span><span class="sy0">:</span><span class="nu0">109.8901</span><span class="sy0">,</span><span class="st0">&quot;KRW&quot;</span><span class="sy0">:</span><span class="nu0">1000</span><span class="sy0">,</span><span class="st0">&quot;LKR&quot;</span><span class="sy0">:</span><span class="nu0">107.5269</span><span class="sy0">,</span><span class="st0">&quot;MXN&quot;</span><span class="sy0">:</span><span class="nu0">10.1317</span><span class="sy0">,</span><span class="st0">&quot;MYR&quot;</span> <span class="sy0">:</span><span class="nu0">3.3167</span><span class="sy0">,</span><span class="st0">&quot;NOK&quot;</span><span class="sy0">:</span><span class="nu0">5.3277</span><span class="sy0">,</span><span class="st0">&quot;SEK&quot;</span><span class="sy0">:</span><span class="nu0">6.2617</span><span class="sy0">,</span><span class="st0">&quot;SGD&quot;</span><span class="sy0">:</span><span class="nu0">1.4073</span><span class="sy0">,</span><span class="st0">&quot;THB&quot;</span><span class="sy0">:</span><span class="nu0">33.7838</span><span class="sy0">,</span><span class="st0">&quot;TWD&quot;</span><span class="sy0">:</span><span class="nu0">31.1526</span><span class="sy0">,</span><span class="st0">&quot;VEF&quot;</span><span class="sy0">:</span><span class="nu0">2.1445</span><span class="sy0">,</span><span class="st0">&quot;ZAR&quot;</span><span class="sy0">:</span><span class="nu0">7.6923</span> <span class="sy0">,</span><span class="st0">&quot;BGN&quot;</span><span class="sy0">:</span><span class="nu0">1.3028</span><span class="sy0">,</span><span class="st0">&quot;CZK&quot;</span><span class="sy0">:</span><span class="nu0">16.0514</span><span class="sy0">,</span><span class="st0">&quot;EEK&quot;</span><span class="sy0">:</span><span class="nu0">10.4275</span><span class="sy0">,</span><span class="st0">&quot;HUF&quot;</span><span class="sy0">:</span><span class="nu0">158.7302</span><span class="sy0">,</span><span class="st0">&quot;LTL&quot;</span><span class="sy0">:</span><span class="nu0">2.2999</span><span class="sy0">,</span><span class="st0">&quot;LVL&quot;</span><span class="sy0">:</span><span class="nu0">0.4692</span><span class="sy0">,</span><span class="st0">&quot;PLN&quot;</span><span class="sy0">:</span><span class="nu0">2.1758</span><span class="sy0">,</span><span class="st0">&quot;RON&quot;</span> <span class="sy0">:</span><span class="nu0">2.3804</span><span class="sy0">,</span><span class="st0">&quot;SKK&quot;</span><span class="sy0">:</span><span class="nu0">20.2429</span><span class="sy0">,</span><span class="st0">&quot;ISK&quot;</span><span class="sy0">:</span><span class="nu0">4.8008</span><span class="sy0">,</span><span class="st0">&quot;HRK&quot;</span><span class="sy0">:</span><span class="nu0">81.3008</span><span class="sy0">,</span><span class="st0">&quot;RUB&quot;</span><span class="sy0">:</span><span class="nu0">24.3309</span><span class="sy0">,</span><span class="st0">&quot;TRY&quot;</span><span class="sy0">:</span><span class="nu0">1.1811</span><span class="sy0">,</span><span class="st0">&quot;PHP&quot;</span><span class="sy0">:</span><span class="nu0">44.2478</span><span class="sy0">,</span><span class="st0">&quot;COP&quot;</span><span class="sy0">:</span><span class="nu0">2000</span> <span class="sy0">,</span><span class="st0">&quot;ARS&quot;</span><span class="sy0">:</span><span class="nu0">3.1289</span><span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li2"><div class="de2">    currency <span class="sy0">:</span> <span class="st0">'USD'</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    convert <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span>k<span class="sy0">,</span>v<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="co1">// 'this' will refer to the object containing the key:value pair,</span></div></li><li class="li1"><div class="de1">        <span class="co1">// so this step will add a new object member while leaving the original</span></div></li><li class="li2"><div class="de2">        <span class="co1">// intact (but formatted to two decimal places).  If the original</span></div></li><li class="li1"><div class="de1">        <span class="co1">// is not needed, just return the converted value.</span></div></li><li class="li1"><div class="de1">        <span class="kw1">if</span> <span class="br0">&#40;</span>k <span class="sy0">===</span> <span class="st0">'Price'</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">            <span class="kw2">var</span> x <span class="sy0">=</span> Math.<span class="me1">round</span><span class="br0">&#40;</span>v <span class="sy0">*</span> example.<span class="me1">rates</span><span class="br0">&#91;</span>example.<span class="me1">currency</span><span class="br0">&#93;</span> <span class="sy0">*</span> <span class="nu0">100</span><span class="br0">&#41;</span> <span class="sy0">/</span> <span class="nu0">100</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="kw1">this</span>.<span class="me1">convertedPrice</span> <span class="sy0">=</span> x.<span class="me1">toFixed</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// added to item</span></div></li><li class="li2"><div class="de2">            <span class="kw1">return</span> v.<span class="me1">toFixed</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// assigned to item.Price</span></div></li><li class="li1"><div class="de1">        <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">        <span class="kw1">return</span> v<span class="sy0">;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li2"><div class="de2">    updateTable <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span>inventory<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        <span class="co1">// Update the column header</span></div></li><li class="li1"><div class="de1">        Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#demo table th span'</span><span class="br0">&#41;</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'innerHTML'</span><span class="sy0">,</span>example.<span class="me1">currency</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">        <span class="kw2">var</span> tbody <span class="sy0">=</span> Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#demo table tbody'</span><span class="br0">&#41;</span><span class="sy0">,</span></div></li><li class="li2"><div class="de2">            html  <span class="sy0">=</span> <span class="br0">&#91;</span><span class="st0">'&lt;table&gt;&lt;tbody&gt;'</span><span class="br0">&#93;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">            rowTemplate <span class="sy0">=</span> <span class="st0">'&lt;tr&gt;&lt;td&gt;{SKU}&lt;/td&gt;&lt;td&gt;{Item}&lt;/td&gt;&lt;td&gt;{Price}&lt;/td&gt;&lt;td&gt;{convertedPrice}&lt;/td&gt;&lt;/tr&gt;'</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">            i<span class="sy0">,</span> len<span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">        <span class="kw1">if</span> <span class="br0">&#40;</span>inventory<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">            <span class="kw1">for</span> <span class="br0">&#40;</span>i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">,</span> len <span class="sy0">=</span> inventory.<span class="me1">length</span><span class="sy0">;</span> i <span class="sy0">&lt;</span> len<span class="sy0">;</span> <span class="sy0">++</span>i<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                html.<span class="me1">push</span><span class="br0">&#40;</span>Y.<span class="me1">Lang</span>.<span class="me1">sub</span><span class="br0">&#40;</span>rowTemplate<span class="sy0">,</span> inventory<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">            <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">        <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">            html.<span class="me1">push</span><span class="br0">&#40;</span><span class="st0">'&lt;tr&gt;&lt;td colspan=&quot;4&quot;&gt;No Inventory data&lt;/td&gt;&lt;/tr&gt;'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">        <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">        html.<span class="me1">push</span><span class="br0">&#40;</span><span class="st0">'&lt;/tbody&gt;&lt;/table&gt;'</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">        tbody.<span class="me1">replace</span><span class="br0">&#40;</span>Y.<span class="me1">Node</span>.<span class="me1">create</span><span class="br0">&#40;</span>html.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">''</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'tbody'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">    <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#demo_go'</span><span class="br0">&#41;</span>.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'click'</span><span class="sy0">,</span> <span class="kw2">function</span> <span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">    <span class="co1">// Disable the button temporarily</span></div></li><li class="li2"><div class="de2">    <span class="kw1">this</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'disabled'</span><span class="sy0">,</span><span class="kw2">true</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">    <span class="co1">// Store the requested currency</span></div></li><li class="li1"><div class="de1">    <span class="kw2">var</span> sel <span class="sy0">=</span> Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">&quot;#demo select&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">    example.<span class="me1">currency</span> <span class="sy0">=</span> sel.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;options&quot;</span><span class="br0">&#41;</span>.<span class="kw1">item</span><span class="br0">&#40;</span>sel.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;selectedIndex&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">&nbsp;</div></li><li class="li1"><div class="de1">    Y.<span class="me1">io</span><span class="br0">&#40;</span><span class="st0">'assets/data.php'</span><span class="sy0">,</span><span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">        timeout <span class="sy0">:</span> <span class="nu0">3000</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">        on <span class="sy0">:</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">            success <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span>xid<span class="sy0">,</span> res<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">                <span class="kw2">var</span> inventory<span class="sy0">;</span></div></li><li class="li1"><div class="de1">                <span class="kw1">try</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                    inventory <span class="sy0">=</span> Y.<span class="me1">JSON</span>.<span class="me1">parse</span><span class="br0">&#40;</span>res.<span class="me1">responseText</span><span class="sy0">,</span>example.<span class="me1">convert</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li1"><div class="de1">                    example.<span class="me1">updateTable</span><span class="br0">&#40;</span>inventory<span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">                <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">                <span class="kw1">catch</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                    <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Error getting inventory data&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">                <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">                <span class="kw1">finally</span> <span class="br0">&#123;</span></div></li><li class="li2"><div class="de2">                    Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#demo_go'</span><span class="br0">&#41;</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'disabled'</span><span class="sy0">,</span><span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">                <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">            <span class="br0">&#125;</span><span class="sy0">,</span></div></li><li class="li1"><div class="de1">            failure <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div></li><li class="li1"><div class="de1">                <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Error getting inventory data&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li2"><div class="de2">            <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">        <span class="br0">&#125;</span></div></li><li class="li1"><div class="de1">    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li><li class="li1"><div class="de1">&nbsp;</div></li><li class="li2"><div class="de2"><span class="co1">// Expose example objects for inspection</span></div></li><li class="li1"><div class="de1">YUI.<span class="me1">example</span> <span class="sy0">=</span> example<span class="sy0">;</span></div></li><li class="li1"><div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div></li></ol></pre></div><div class="nonumbers"><pre class="javascript" style="font-family:monospace;">YUI<span class="br0">&#40;</span><span class="br0">&#123;</span> filter<span class="sy0">:</span> <span class="st0">'raw'</span> <span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="kw2">use</span><span class="br0">&#40;</span><span class="st0">&quot;node&quot;</span><span class="sy0">,</span> <span class="st0">&quot;io&quot;</span><span class="sy0">,</span> <span class="st0">&quot;json-parse&quot;</span><span class="sy0">,</span><span class="kw2">function</span> <span class="br0">&#40;</span>Y<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp;
<span class="co1">// Safari 4.0.3's native JSON does not support adding members during parse,</span>
<span class="co1">// so use JavaScript implementation for consistency</span>
Y.<span class="me1">JSON</span>.<span class="me1">useNativeParse</span> <span class="sy0">=</span> <span class="kw2">false</span><span class="sy0">;</span>
&nbsp;
<span class="kw2">var</span> example <span class="sy0">=</span> <span class="br0">&#123;</span>
    rates <span class="sy0">:</span> <span class="br0">&#123;</span><span class="st0">&quot;USD&quot;</span><span class="sy0">:</span><span class="nu0">1</span><span class="sy0">,</span><span class="st0">&quot;EUR&quot;</span><span class="sy0">:</span><span class="nu0">0.6661</span><span class="sy0">,</span><span class="st0">&quot;GBP&quot;</span><span class="sy0">:</span><span class="nu0">0.5207</span><span class="sy0">,</span><span class="st0">&quot;AUD&quot;</span><span class="sy0">:</span><span class="nu0">1.1225</span><span class="sy0">,</span><span class="st0">&quot;BRL&quot;</span><span class="sy0">:</span><span class="nu0">1.609</span><span class="sy0">,</span><span class="st0">&quot;NZD&quot;</span><span class="sy0">:</span><span class="nu0">1.4198</span><span class="sy0">,</span><span class="st0">&quot;CAD&quot;</span><span class="sy0">:</span><span class="nu0">1.0667</span><span class="sy0">,</span><span class="st0">&quot;CHF&quot;</span><span class="sy0">:</span><span class="nu0">1.0792</span><span class="sy0">,</span><span class="st0">&quot;CNY&quot;</span><span class="sy0">:</span><span class="nu0">6.8587</span> <span class="sy0">,</span><span class="st0">&quot;DKK&quot;</span><span class="sy0">:</span><span class="nu0">4.9702</span><span class="sy0">,</span><span class="st0">&quot;HKD&quot;</span><span class="sy0">:</span><span class="nu0">7.8064</span><span class="sy0">,</span><span class="st0">&quot;INR&quot;</span><span class="sy0">:</span><span class="nu0">42.0168</span><span class="sy0">,</span><span class="st0">&quot;JPY&quot;</span><span class="sy0">:</span><span class="nu0">109.8901</span><span class="sy0">,</span><span class="st0">&quot;KRW&quot;</span><span class="sy0">:</span><span class="nu0">1000</span><span class="sy0">,</span><span class="st0">&quot;LKR&quot;</span><span class="sy0">:</span><span class="nu0">107.5269</span><span class="sy0">,</span><span class="st0">&quot;MXN&quot;</span><span class="sy0">:</span><span class="nu0">10.1317</span><span class="sy0">,</span><span class="st0">&quot;MYR&quot;</span> <span class="sy0">:</span><span class="nu0">3.3167</span><span class="sy0">,</span><span class="st0">&quot;NOK&quot;</span><span class="sy0">:</span><span class="nu0">5.3277</span><span class="sy0">,</span><span class="st0">&quot;SEK&quot;</span><span class="sy0">:</span><span class="nu0">6.2617</span><span class="sy0">,</span><span class="st0">&quot;SGD&quot;</span><span class="sy0">:</span><span class="nu0">1.4073</span><span class="sy0">,</span><span class="st0">&quot;THB&quot;</span><span class="sy0">:</span><span class="nu0">33.7838</span><span class="sy0">,</span><span class="st0">&quot;TWD&quot;</span><span class="sy0">:</span><span class="nu0">31.1526</span><span class="sy0">,</span><span class="st0">&quot;VEF&quot;</span><span class="sy0">:</span><span class="nu0">2.1445</span><span class="sy0">,</span><span class="st0">&quot;ZAR&quot;</span><span class="sy0">:</span><span class="nu0">7.6923</span> <span class="sy0">,</span><span class="st0">&quot;BGN&quot;</span><span class="sy0">:</span><span class="nu0">1.3028</span><span class="sy0">,</span><span class="st0">&quot;CZK&quot;</span><span class="sy0">:</span><span class="nu0">16.0514</span><span class="sy0">,</span><span class="st0">&quot;EEK&quot;</span><span class="sy0">:</span><span class="nu0">10.4275</span><span class="sy0">,</span><span class="st0">&quot;HUF&quot;</span><span class="sy0">:</span><span class="nu0">158.7302</span><span class="sy0">,</span><span class="st0">&quot;LTL&quot;</span><span class="sy0">:</span><span class="nu0">2.2999</span><span class="sy0">,</span><span class="st0">&quot;LVL&quot;</span><span class="sy0">:</span><span class="nu0">0.4692</span><span class="sy0">,</span><span class="st0">&quot;PLN&quot;</span><span class="sy0">:</span><span class="nu0">2.1758</span><span class="sy0">,</span><span class="st0">&quot;RON&quot;</span> <span class="sy0">:</span><span class="nu0">2.3804</span><span class="sy0">,</span><span class="st0">&quot;SKK&quot;</span><span class="sy0">:</span><span class="nu0">20.2429</span><span class="sy0">,</span><span class="st0">&quot;ISK&quot;</span><span class="sy0">:</span><span class="nu0">4.8008</span><span class="sy0">,</span><span class="st0">&quot;HRK&quot;</span><span class="sy0">:</span><span class="nu0">81.3008</span><span class="sy0">,</span><span class="st0">&quot;RUB&quot;</span><span class="sy0">:</span><span class="nu0">24.3309</span><span class="sy0">,</span><span class="st0">&quot;TRY&quot;</span><span class="sy0">:</span><span class="nu0">1.1811</span><span class="sy0">,</span><span class="st0">&quot;PHP&quot;</span><span class="sy0">:</span><span class="nu0">44.2478</span><span class="sy0">,</span><span class="st0">&quot;COP&quot;</span><span class="sy0">:</span><span class="nu0">2000</span> <span class="sy0">,</span><span class="st0">&quot;ARS&quot;</span><span class="sy0">:</span><span class="nu0">3.1289</span><span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
    currency <span class="sy0">:</span> <span class="st0">'USD'</span><span class="sy0">,</span>
&nbsp;
    convert <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span>k<span class="sy0">,</span>v<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="co1">// 'this' will refer to the object containing the key:value pair,</span>
        <span class="co1">// so this step will add a new object member while leaving the original</span>
        <span class="co1">// intact (but formatted to two decimal places).  If the original</span>
        <span class="co1">// is not needed, just return the converted value.</span>
        <span class="kw1">if</span> <span class="br0">&#40;</span>k <span class="sy0">===</span> <span class="st0">'Price'</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="kw2">var</span> x <span class="sy0">=</span> Math.<span class="me1">round</span><span class="br0">&#40;</span>v <span class="sy0">*</span> example.<span class="me1">rates</span><span class="br0">&#91;</span>example.<span class="me1">currency</span><span class="br0">&#93;</span> <span class="sy0">*</span> <span class="nu0">100</span><span class="br0">&#41;</span> <span class="sy0">/</span> <span class="nu0">100</span><span class="sy0">;</span>
            <span class="kw1">this</span>.<span class="me1">convertedPrice</span> <span class="sy0">=</span> x.<span class="me1">toFixed</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// added to item</span>
            <span class="kw1">return</span> v.<span class="me1">toFixed</span><span class="br0">&#40;</span><span class="nu0">2</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">// assigned to item.Price</span>
        <span class="br0">&#125;</span>
        <span class="kw1">return</span> v<span class="sy0">;</span>
    <span class="br0">&#125;</span><span class="sy0">,</span>
&nbsp;
    updateTable <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span>inventory<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        <span class="co1">// Update the column header</span>
        Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#demo table th span'</span><span class="br0">&#41;</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'innerHTML'</span><span class="sy0">,</span>example.<span class="me1">currency</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
        <span class="kw2">var</span> tbody <span class="sy0">=</span> Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#demo table tbody'</span><span class="br0">&#41;</span><span class="sy0">,</span>
            html  <span class="sy0">=</span> <span class="br0">&#91;</span><span class="st0">'&lt;table&gt;&lt;tbody&gt;'</span><span class="br0">&#93;</span><span class="sy0">,</span>
            rowTemplate <span class="sy0">=</span> <span class="st0">'&lt;tr&gt;&lt;td&gt;{SKU}&lt;/td&gt;&lt;td&gt;{Item}&lt;/td&gt;&lt;td&gt;{Price}&lt;/td&gt;&lt;td&gt;{convertedPrice}&lt;/td&gt;&lt;/tr&gt;'</span><span class="sy0">,</span>
            i<span class="sy0">,</span> len<span class="sy0">;</span>
&nbsp;
        <span class="kw1">if</span> <span class="br0">&#40;</span>inventory<span class="br0">&#41;</span> <span class="br0">&#123;</span>
            <span class="kw1">for</span> <span class="br0">&#40;</span>i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">,</span> len <span class="sy0">=</span> inventory.<span class="me1">length</span><span class="sy0">;</span> i <span class="sy0">&lt;</span> len<span class="sy0">;</span> <span class="sy0">++</span>i<span class="br0">&#41;</span> <span class="br0">&#123;</span>
                html.<span class="me1">push</span><span class="br0">&#40;</span>Y.<span class="me1">Lang</span>.<span class="me1">sub</span><span class="br0">&#40;</span>rowTemplate<span class="sy0">,</span> inventory<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="br0">&#125;</span>
        <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
            html.<span class="me1">push</span><span class="br0">&#40;</span><span class="st0">'&lt;tr&gt;&lt;td colspan=&quot;4&quot;&gt;No Inventory data&lt;/td&gt;&lt;/tr&gt;'</span><span class="br0">&#41;</span><span class="sy0">;</span>
        <span class="br0">&#125;</span>
&nbsp;
        html.<span class="me1">push</span><span class="br0">&#40;</span><span class="st0">'&lt;/tbody&gt;&lt;/table&gt;'</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
        tbody.<span class="me1">replace</span><span class="br0">&#40;</span>Y.<span class="me1">Node</span>.<span class="me1">create</span><span class="br0">&#40;</span>html.<span class="me1">join</span><span class="br0">&#40;</span><span class="st0">''</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'tbody'</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    <span class="br0">&#125;</span>
<span class="br0">&#125;</span><span class="sy0">;</span>
&nbsp;
Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#demo_go'</span><span class="br0">&#41;</span>.<span class="me1">on</span><span class="br0">&#40;</span><span class="st0">'click'</span><span class="sy0">,</span> <span class="kw2">function</span> <span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="co1">// Disable the button temporarily</span>
    <span class="kw1">this</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'disabled'</span><span class="sy0">,</span><span class="kw2">true</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    <span class="co1">// Store the requested currency</span>
    <span class="kw2">var</span> sel <span class="sy0">=</span> Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">&quot;#demo select&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
    example.<span class="me1">currency</span> <span class="sy0">=</span> sel.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;options&quot;</span><span class="br0">&#41;</span>.<span class="kw1">item</span><span class="br0">&#40;</span>sel.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;selectedIndex&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&quot;value&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
    Y.<span class="me1">io</span><span class="br0">&#40;</span><span class="st0">'assets/data.php'</span><span class="sy0">,</span><span class="br0">&#123;</span>
        timeout <span class="sy0">:</span> <span class="nu0">3000</span><span class="sy0">,</span>
        on <span class="sy0">:</span> <span class="br0">&#123;</span>
            success <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span>xid<span class="sy0">,</span> res<span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="kw2">var</span> inventory<span class="sy0">;</span>
                <span class="kw1">try</span> <span class="br0">&#123;</span>
                    inventory <span class="sy0">=</span> Y.<span class="me1">JSON</span>.<span class="me1">parse</span><span class="br0">&#40;</span>res.<span class="me1">responseText</span><span class="sy0">,</span>example.<span class="me1">convert</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
                    example.<span class="me1">updateTable</span><span class="br0">&#40;</span>inventory<span class="br0">&#41;</span><span class="sy0">;</span>
                <span class="br0">&#125;</span>
                <span class="kw1">catch</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span>
                    <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Error getting inventory data&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
                <span class="br0">&#125;</span>
                <span class="kw1">finally</span> <span class="br0">&#123;</span>
                    Y.<span class="me1">one</span><span class="br0">&#40;</span><span class="st0">'#demo_go'</span><span class="br0">&#41;</span>.<span class="me1">set</span><span class="br0">&#40;</span><span class="st0">'disabled'</span><span class="sy0">,</span><span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span>
                <span class="br0">&#125;</span>
            <span class="br0">&#125;</span><span class="sy0">,</span>
            failure <span class="sy0">:</span> <span class="kw2">function</span> <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
                <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Error getting inventory data&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
            <span class="br0">&#125;</span>
        <span class="br0">&#125;</span>
    <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
<span class="co1">// Expose example objects for inspection</span>
YUI.<span class="me1">example</span> <span class="sy0">=</span> example<span class="sy0">;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div><textarea id="syntax-fbd938cb61eb0c597e08c5f48e64f802-plain">YUI({ filter: 'raw' }).use("node", "io", "json-parse",function (Y) {

// Safari 4.0.3's native JSON does not support adding members during parse,
// so use JavaScript implementation for consistency
Y.JSON.useNativeParse = false;

var example = {
    rates : {"USD":1,"EUR":0.6661,"GBP":0.5207,"AUD":1.1225,"BRL":1.609,"NZD":1.4198,"CAD":1.0667,"CHF":1.0792,"CNY":6.8587 ,"DKK":4.9702,"HKD":7.8064,"INR":42.0168,"JPY":109.8901,"KRW":1000,"LKR":107.5269,"MXN":10.1317,"MYR" :3.3167,"NOK":5.3277,"SEK":6.2617,"SGD":1.4073,"THB":33.7838,"TWD":31.1526,"VEF":2.1445,"ZAR":7.6923 ,"BGN":1.3028,"CZK":16.0514,"EEK":10.4275,"HUF":158.7302,"LTL":2.2999,"LVL":0.4692,"PLN":2.1758,"RON" :2.3804,"SKK":20.2429,"ISK":4.8008,"HRK":81.3008,"RUB":24.3309,"TRY":1.1811,"PHP":44.2478,"COP":2000 ,"ARS":3.1289},

    currency : 'USD',

    convert : function (k,v) {
        // 'this' will refer to the object containing the key:value pair,
        // so this step will add a new object member while leaving the original
        // intact (but formatted to two decimal places).  If the original
        // is not needed, just return the converted value.
        if (k === 'Price') {
            var x = Math.round(v * example.rates[example.currency] * 100) / 100;
            this.convertedPrice = x.toFixed(2); // added to item
            return v.toFixed(2); // assigned to item.Price
        }
        return v;
    },

    updateTable : function (inventory) {
        // Update the column header
        Y.one('#demo table th span').set('innerHTML',example.currency);

        var tbody = Y.one('#demo table tbody'),
            html  = ['<table><tbody>'],
            rowTemplate = '<tr><td>{SKU}</td><td>{Item}</td><td>{Price}</td><td>{convertedPrice}</td></tr>',
            i, len;

        if (inventory) {
            for (i = 0, len = inventory.length; i < len; ++i) {
                html.push(Y.Lang.sub(rowTemplate, inventory[i]));
            }
        } else {
            html.push('<tr><td colspan="4">No Inventory data</td></tr>');
        }

        html.push('</tbody></table>');

        tbody.replace(Y.Node.create(html.join('')).one('tbody'));
    }
};

Y.one('#demo_go').on('click', function (e) {
    // Disable the button temporarily
    this.set('disabled',true);

    // Store the requested currency
    var sel = Y.one("#demo select");
    example.currency = sel.get("options").item(sel.get("selectedIndex")).get("value");

    Y.io('assets/data.php',{
        timeout : 3000,
        on : {
            success : function (xid, res) {
                var inventory;
                try {
                    inventory = Y.JSON.parse(res.responseText,example.convert);

                    example.updateTable(inventory);
                }
                catch(e) {
                    alert("Error getting inventory data");
                }
                finally {
                    Y.one('#demo_go').set('disabled',false);
                }
            },
            failure : function () {
                alert("Error getting inventory data");
            }
        }
    });
});

// Expose example objects for inspection
YUI.example = example;
});</textarea></div>				</div>
				<div class="yui-u sidebar">
	
					<div id="examples" class="mod box4">
                        <div class="hd">
						<h4>
    JSON Examples:</h4>
                        </div>
						<div class="bd">
							<ul>
								<li><a href='../json/json_connect.html'>JSON with Y.io</a></li><li><a href='../json/json_freeze_thaw.html'>Rebuilding Class Instances from JSON Data</a></li><li class='selected'><a href='../json/json_convert_values.html'>Adding New Object Members During Parsing</a></li>							</ul>
						</div>
					</div>

					<div class="mod box4">
                        <div class="hd">
						<h4>More JSON Resources:</h4>
                        </div>
                        <div class="bd">
						<ul>
							<!-- <li><a href="http://developer.yahoo.com/yui/json/">User's Guide</a> (external)</li> -->
<li><a href="../../api/module_json.html">API Documentation</a></li></ul>
                        </div>
					</div>
			  </div>
		</div>

		</div>
	</div>


<div class="yui-b toc3" id="tocWrapper">
<!-- TABLE OF CONTENTS -->
<div id="toc">
	
<ul>
<li class="sect first">YUI 3 Resources</li><li class="item"><a title="YUI 3 -- Yahoo! User Interface (YUI) Library" href="http://developer.yahoo.com/yui/3/">YUI 3 Web Site</a></li><li class="item"><a title="Examples of every YUI utility and control in action" href="../../examples/">YUI 3 Examples</a></li><li class="item"><a title="Instantly searchable API documentation for the entire YUI library." href="../../api/">YUI 3 API Docs</a></li><li class="item"><a title="YUI 3 Dependency Configurator -- configure your custom YUI implementation" href="http://developer.yahoo.com/yui/3/configurator/index.html">YUI 3 Dependency Configurator</a></li><li class="item"><a title="The YUI 3 Forum on YUILibrary.com" href="http://yuilibrary.com/forum/viewforum.php?f=15">YUI 3 Forums (external)</a></li><li class="item"><a title="Found a bug or a missing feature? Let us know on YUILibrary.com." href="http://developer.yahoo.com/yui/articles/reportingbugs/">Bug Reports/Feature Requests</a></li><li class="item"><a title="YUI is free and open, offered under a BSD license." href="http://developer.yahoo.com/yui/license.html">YUI License</a></li><li class="item"><a title="Download and fork the YUI project on GitHub" href="http://github.com/yui">YUI on Github</a></li><li class="item"><a title="The Yahoo! User Interface Blog" href="http://yuiblog.com">YUI Blog (external)</a></li><li class="sect">YUI 3 Core - Examples</li><li class="item"><a title="YUI Global Object - Functional Examples" href="../../examples/yui/index.html">YUI Global Object</a></li><li class="item"><a title="Event - Functional Examples" href="../../examples/event/index.html">Event</a></li><li class="item"><a title="Node - Functional Examples" href="../../examples/node/index.html">Node</a></li><li class="sect">YUI 3 Component Infrastructure - Examples</li><li class="item"><a title="Attribute - Functional Examples" href="../../examples/attribute/index.html">Attribute</a></li><li class="item"><a title="Plugin - Functional Examples" href="../../examples/plugin/index.html">Plugin</a></li><li class="item"><a title="Widget - Functional Examples" href="../../examples/widget/index.html">Widget</a></li><li class="sect">YUI 3 Utilities - Examples</li><li class="item"><a title="Animation - Functional Examples" href="../../examples/anim/index.html">Animation</a></li><li class="item"><a title="AsyncQueue - Functional Examples" href="../../examples/async-queue/index.html">AsyncQueue</a></li><li class="item"><a title="Cache - Functional Examples" href="../../examples/cache/index.html">Cache</a></li><li class="item"><a title="Cookie - Functional Examples" href="../../examples/cookie/index.html">Cookie</a></li><li class="item"><a title="DataSchema - Functional Examples" href="../../examples/dataschema/index.html">DataSchema <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="DataSource - Functional Examples" href="../../examples/datasource/index.html">DataSource <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="DataType - Functional Examples" href="../../examples/datatype/index.html">DataType <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Drag &amp; Drop - Functional Examples" href="../../examples/dd/index.html">Drag &amp; Drop</a></li><li class="item"><a title="Get - Functional Examples" href="../../examples/get/index.html">Get</a></li><li class="item"><a title="History - Functional Examples" href="../../examples/history/index.html">History <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="IO - Functional Examples" href="../../examples/io/index.html">IO</a></li><li class="item"><a title="ImageLoader - Functional Examples" href="../../examples/imageloader/index.html">ImageLoader</a></li><li class="item"><a title="Internationalization - Functional Examples" href="../../examples/intl/index.html">Internationalization</a></li><li class="selected "><a title="JSON (JavaScript Object Notation) - Functional Examples" href="../../examples/json/index.html">JSON</a></li><li class="item"><a title="JSONP (JSON with Padding) - Functional Examples" href="../../examples/jsonp/index.html">JSONP <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Recordset - Functional Examples" href="../../examples/recordset/index.html">Recordset <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Resize - Functional Examples" href="../../examples/resize/index.html">Resize <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Sortable - Functional Examples" href="../../examples/sortable/index.html">Sortable <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Stylesheet - Functional Examples" href="../../examples/stylesheet/index.html">Stylesheet</a></li><li class="item"><a title="Transition - Functional Examples" href="../../examples/transition/index.html">Transition <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Uploader - Functional Examples" href="../../examples/uploader/index.html">Uploader <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="YQL Query - Functional Examples" href="../../examples/yql/index.html">YQL Query <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 Widgets - Examples</li><li class="item"><a title="AutoComplete - Functional Examples" href="../../examples/autocomplete/index.html">AutoComplete <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Charts - Functional Examples" href="../../examples/charts/index.html">Charts <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="DataTable - Functional Examples" href="../../examples/datatable/index.html">DataTable <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Dial - Functional Examples" href="../../examples/dial/index.html">Dial <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Editor - Functional Examples" href="../../examples/editor/index.html">Editor <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Overlay - Functional Examples" href="../../examples/overlay/index.html">Overlay <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="ScrollView - Functional Examples" href="../../examples/scrollview/index.html">ScrollView <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Slider - Functional Examples" href="../../examples/slider/index.html">Slider <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="TabView - Functional Examples" href="../../examples/tabview/index.html">TabView <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 Node Plugins - Examples</li><li class="item"><a title="FocusManager Node Plugin - Functional Examples" href="../../examples/node-focusmanager/index.html">FocusManager Node Plugin <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="MenuNav Node Plugin - Functional Examples" href="../../examples/node-menunav/index.html">MenuNav Node Plugin <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="sect">YUI 3 CSS - Examples</li><li class="item"><a title="YUI Base - Functional Examples" href="../../examples/cssbase/index.html">CSS Base</a></li><li class="item"><a title="YUI Fonts - Functional Examples" href="../../examples/cssfonts/index.html">CSS Fonts</a></li><li class="item"><a title="YUI Grids - Functional Examples" href="../../examples/cssgrids/index.html">CSS Grids <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="YUI CSS Reset - Functional Examples" href="../../examples/cssreset/index.html">CSS Reset</a></li><li class="sect">YUI 3 Developer Tools - Examples</li><li class="item"><a title="Console - Functional Examples" href="../../examples/console/index.html">Console <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Console Filters Plugin- Functional Examples" href="../../examples/console-filters/index.html">Plugin.ConsoleFilters <img alt='beta' src='http://l.yimg.com/a/i/not/beta_1.gif'></a></li><li class="item"><a title="Profiler - Functional Examples" href="../../examples/profiler/index.html">Profiler</a></li><li class="item"><a title="Test - Functional Examples" href="../../examples/test/index.html">Test</a></li><li class="sect">Other Useful YUI 3 Resources</li><li class="item"><a title="Answers to Frequently Asked Questions about the YUI Library" href="http://developer.yahoo.com/yui/articles/faq/">YUI FAQ (external)</a></li><li class="item"><a title="Yahoo!'s philosophy of Graded Browser Support" href="http://developer.yahoo.com/yui/articles/gbs/">Graded Browser Support (external)</a></li><li class="item"><a title="Videos and podcasts from the YUI Team and from the Yahoo! frontend engineering community." href="http://developer.yahoo.com/yui/theater/">YUI Theater (external)</a></li></ul>
</div>
</div>
	</div><!--closes bd-->

	<div id="ft">
        <p class="first">Copyright &copy; 2011 Yahoo! Inc. All rights reserved.</p>
        <p><a href="http://privacy.yahoo.com/privacy/us/devel/index.html">Privacy Policy</a> - 
            <a href="http://docs.yahoo.com/info/terms/">Terms of Service</a> - 
            <a href="http://docs.yahoo.com/info/copyright/copyright.html">Copyright Policy</a> - 
            <a href="http://careers.yahoo.com/">Job Openings</a></p>
	</div>
</div>
<script language="javascript"> 
var yuiConfig = { filter: 'raw' };
</script>
<script src="../../assets/syntax.js"></script>
<script src="../../assets/dpSyntaxHighlighter.js"></script>
<script language="javascript"> 
dp.SyntaxHighlighter.HighlightAll('code'); 
</script>
</body>
</html>
